﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Data.SqlTypes;

namespace Team4
{
    /// <summary>
    /// Summary description for schedulerWebService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class schedulerWebService : System.Web.Services.WebService
    {

        //! GetEventsForDynoInRange
        /*!
         * DESCRIPTION:
         *  
         * Get events for specified room scheduled within a data range from database
         * 
         * PARAMETERS:
         * 
         * startDateRange - start date
         * 
         * endDateRange - end date
         * 
         * roomCode - room code
         * 
         * RETURN:
         * 
         * event array
         * 
         * REVISIONS:
         * 10/19/2011 - IMK - Created.
         */
        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
        public BLL.CalendarEvent[] GetEventsForRoomInRange(string startDateRange, string endDateRange, string roomCode)
        {
            // Get CalendarEvent objects from database here.
            return BLL.CalendarEvent.GetEventsForRoomInRange(startDateRange, endDateRange, roomCode);
        }

        //! SaveEvent
        /*!
         * DESCRIPTION:
         *  
         * Save event in database.
         * 
         * PARAMETERS:
         * 
         * all database event fields
         * 
         * RETURN:
         * 
         * string if successful or error code if not
         * 
         * REVISIONS:
         * 10/19/2011 - IMK - Created.
         */
        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string SaveEventString(string Id, string Title, string AllDay, string Start, string End,
                                string Url, string ClassName, string Editable, string RoomCode)
        {
            try
            {
                // Save it here.
                new BLL.CalendarEvent(Id, Title, AllDay, Start, End, Url, ClassName, Editable, RoomCode, User.Identity.Name).Save();

                return "Updated Successfully!";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
    }
}
